var specId = '';
var detail = {
	init:function(){
        this.layuiUse();	
        this.scroll();
        this.proDetailClick();
        this.goBuy();
	},
	layuiUse:function(){
		layui.use(['layer', 'carousel','jquery','form'], function(){
            var layer = layui.layer,
                carousel = layui.carousel,
                form = layui.form,
                $ = layui.$;
            
            //detailTitle 商品、详情--点击滚动
            $('.detailTitle1').on('click',function(){
                $('.detailTitle1').addClass('detailNow');
                $('.detailTitle2').removeClass('detailNow');
                window.scrollTo({ 
                    top: 50, 
                    behavior: "smooth" 
                });
            });
            $('.detailTitle2').on('click',function(){
                $('.detailTitle1').removeClass('detailNow');
                $('.detailTitle2').addClass('detailNow');
                window.scrollTo({ 
                    top: 500, 
                    behavior: "smooth" 
                });
            });
        });
    },
    scroll:function(){
        $(window).bind('scroll',function(){
            var scrollHeight=document.documentElement.scrollTop||document.body.scrollTop;
            if(scrollHeight>490){
                $('.detailTitle1').removeClass('detailNow');
                $('.detailTitle2').addClass('detailNow');
            }else{
                $('.detailTitle1').addClass('detailNow');
                $('.detailTitle2').removeClass('detailNow');
            }
        });
    },
    // 商品介绍/规格 切换
    proDetailClick:function(){
        $('.proTitle').on('click',function(){
            $('.proTitle').removeClass('proNow');
            $(this).addClass('proNow');
            if($(this).attr('name')=='proBox1'){
                $('.proBox1').removeClass('hide');
                $('.proBox2').addClass('hide');
            }else{
                $('.proBox1').addClass('hide');
                $('.proBox2').removeClass('hide');
            }
        });
    },
    // 立即领取
    goBuy:function(){
        //判断用户是否登录
        let isTokenNow = public.isToken();
        $('body').on('click','span[name="goBuy"]',function () {
            console.log(isTokenNow,'hhhhhhhhhhhhhh');
            if(isTokenNow!=10000){
                layer.msg('<p class="colorSystem font16 alignC mt15">请您先登录~</p>',{time:600},function(){
                    window.location.href="../../html/login/login.html";
                });
            }else{
                let isTokenNow = public.isToken();
                if(isTokenNow!=10000){
                    layui.use(['layer'], function(){
                        var layer = layui.layer;
                        layer.msg('<p class="colorSystem font16 alignC mt15">请您先登录~</p>',{time:600},function(){
                            window.location.href="../../html/login/login.html";
                        });
                    });
                }else{
                    $.ajax({
                        type: 'post',
                        url: link + '/mobile/order/ready',
                        data: {
                            'token':GetCookie('token'),
                        },
                        dataType: 'json',
                        success: function (res) {
                            console.log(res);
                            if(res.code==10000){
                                window.location.href='../../html/order/order.html?orderId='+'3333';
                            }else if(res.code==10022){
                                layui.use(['layer'], function(){
                                    var layer = layui.layer;
                                    layer.msg('<p class="colorSystem font16 alignC mt15">您有未支付订单，请您先支付哦~</p>',{time:600},function(){
                                        window.location.href="../../html/person/orderList.html?type=2";
                                    });
                                });
                            }else if(res.code==40003){
                                layui.use(['layer'], function(){
                                    var layer = layui.layer;
                                    layer.msg('<p class="colorSystem font16 alignC mt15">请您先登录~</p>',{time:600},function(){
                                        window.location.href="../../html/login/login.html";
                                    });
                                });
                            }
                        },
                        error: function (res) {
            
                        },
                    });
                }
               
            }
            
        });
    },
}
detail.init();

          